﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;

namespace MMK.PaketTracker.Server.Helpers
{
	public static class LogHelper
	{
		public static string LogFolder
		{
			get
			{
				if (HttpContext.Current != null && HttpContext.Current.Server != null)
				{
					return HttpContext.Current.Server.MapPath("Log");
				}
				
				return Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Log");
			}
		}

		public static string LogFile
		{
			get
			{
				return Path.Combine(LogFolder, System.DateTime.Now.ToString("yyyyMMdd") + ".log");
			}
		}
		
		public static void WriteLog(string logText)
		{
			if (!Directory.Exists(LogFile))
				Directory.CreateDirectory(LogFolder);

			logText = String.Format("[{0}]: {1}", System.DateTime.Now.ToString("HH:mm:ss"), logText);

			StreamWriter srWriter = new StreamWriter(LogFile, true);
			Console.WriteLine(logText);
			srWriter.WriteLine(logText);
			srWriter.Flush();
			srWriter.Close();
		}
	}
}
